package com.hjm.project.merchantInfo.merRecord.controller;

import java.util.List;

import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.project.merchantInfo.merRecord.domain.MerRecord;
import com.hjm.project.merchantInfo.merRecord.service.IMerRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 商户换机,商户迁移Controller
 * 
 * @author maker-platform
 * @date 2021-04-01
 */
@Controller
@RequestMapping("/merRecord/merRecord")
public class MerRecordController extends BaseController
{
    private String prefix = "merchantInfo/merRecord";

    @Resource
    private IMerRecordService merRecordService;

    @RequiresPermissions("merRecord:merRecord:view")
    @GetMapping()
    public String merRecord()
    {
        return prefix + "/merRecord";
    }

    @RequiresPermissions("merRecord:merRecord:view")
    @GetMapping("/merRecordAgent")
    public String merRecordAgent()
    {
        return prefix + "/merRecordAgent";
    }


    @RequiresPermissions("merRecord:merRecord:view")
    @GetMapping("/merRecordUpdate")
    public String merRecordUpdate()
    {
        return prefix + "/merRecordUpdate";
    }

    /**
     * 查询商户换机,商户迁移列表
     */
    @RequiresPermissions("merRecord:merRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerRecord merRecord)
    {
        startPage();
        List<MerRecord> list = merRecordService.selectMerRecordList(merRecord);
        return getDataTable(list);
    }

    /**
     * 导出商户换机,商户迁移列表
     */
    @RequiresPermissions("merRecord:merRecord:export")
    @Log(title = "商户换机,商户迁移", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerRecord merRecord)
    {
        List<MerRecord> list = merRecordService.selectMerRecordList(merRecord);
        ExcelUtil<MerRecord> util = new ExcelUtil<MerRecord>(MerRecord.class);
        return util.exportExcel(list, "merRecord");
    }

    /**
     * 新增商户换机,商户迁移
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户换机,商户迁移
     */
    @RequiresPermissions("merRecord:merRecord:add")
    @Log(title = "商户换机,商户迁移", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MerRecord merRecord)
    {
        return toAjax(merRecordService.insertMerRecord(merRecord));
    }

    /**
     * 修改商户换机,商户迁移
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        MerRecord merRecord = merRecordService.selectMerRecordById(id);
        mmap.put("merRecord", merRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户换机,商户迁移
     */
    @RequiresPermissions("merRecord:merRecord:edit")
    @Log(title = "商户换机,商户迁移", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MerRecord merRecord)
    {
        return toAjax(merRecordService.updateMerRecord(merRecord));
    }

    /**
     * 删除商户换机,商户迁移
     */
    @RequiresPermissions("merRecord:merRecord:remove")
    @Log(title = "商户换机,商户迁移", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(merRecordService.deleteMerRecordByIds(ids));
    }
}
